package com.que.owen.model;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.io.Serializable;

/**
 * Created by cldong on 10/30/2017.
 */
public class PageQuery implements Serializable, Pageable {
    @Max(value = 50, message = "{page.size.max}")
    @Min(value = 5, message = "{page.size.min}")
    private Integer pageSize;
    @Min(value = 1, message = "{current.page.min}")
    private Integer currentPage;
    private Sort sort;

    public PageQuery() {
    }

    public PageQuery(Integer pageSize, Integer currentPage) {
        this.pageSize = pageSize;
        this.currentPage = currentPage;
    }

    @Override
    public int getPageNumber() {
        return currentPage;
    }

    @Override
    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    @Override
    public int getOffset() {
        return (currentPage - 1) * pageSize;
    }

    @Override
    public Sort getSort() {
        return sort;
    }

    public void setSort(Sort sort) {
        this.sort = sort;
    }

    @Override
    public Pageable next() {
        return null;
    }

    @Override
    public Pageable previousOrFirst() {
        return null;
    }

    @Override
    public Pageable first() {
        return null;
    }

    @Override
    public boolean hasPrevious() {
        return false;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }
}
